﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Betop.Lib.Core.Base;
using Betop.Lib.Utilities;
using Betop.Lib.Core.User;

namespace Betop.Lib.Core.Dept
{
    class DeptDAL : BaseDAL
    {
        /// <summary>
        /// 获得某一部门下直属的用户ID集合
        /// </summary>
        /// <param name="lstDeptIDs"></param>
        /// <returns></returns>
        public List<int> GetUserIDs(IEnumerable<int> lstDeptIDs)
        {
            string deptIDs = ConvertUtil.ConvertToDbStr(lstDeptIDs);
            string sql = "select UserID from DeptUser where DeptID in (" + deptIDs + ")";
            IEnumerable<int> users = dbOper.Query<int>(sql);
            return users.ToList();
        }

        /// <summary>
        /// 用于业务逻辑层计算每一个部门的人数
        /// </summary>
        /// <returns></returns>
        public List<DeptUser> GetUserCount()
        {
            string sql = "select * from DeptUser";
            List<DeptUser> deptUser = dbOper.Query<DeptUser>(sql);
            return deptUser;
        }

        public List<UserInfo> GetUserList(IEnumerable<int> lstDeptIDs)
        {
            List<int> userIDs = GetUserIDs(lstDeptIDs);

            string strUserIDs = ConvertUtil.ConvertToDbStr(userIDs);

            string sql = "select * from [User] where ID in (" + strUserIDs + ")";


            List<UserInfo> users = dbOper.Query<UserInfo>(sql);

            return users;
        }


    }
}
